home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_c / cuj0696.zip / DWYER.ZIP / COUPON.TST / CUPNPROB.C < prev    next >
C/C++ Source or Header  |  1995-12-01  |  1KB  |  42 lines

  1. /* ============ */
  2. /* cupnprob.c    */
  3. /* ============ */
  4. #include <defcodes.h>
  5. #include <math.h>
  6. #include <mconf.h>
  7. #include <miscdefs.h>
  8. /* ==================================================================== */
  9. /* CalcCouponProbs - Computes Probabilities for Coupon Collector's Test    */
  10. /* ==================================================================== */
  11. void
  12. CalcCouponProbs(int SetSize, int MaxLength, double *CouponProbs)
  13. {
  14.     double  ProbCoef;
  15.     int     r;
  16.  
  17.     ProbCoef = exp(lgam(SetSize+1) - (SetSize - 1) * log(SetSize));
  18.  
  19.     P(printf("ProbCoef = %.15e\n", ProbCoef));
  20.  
  21.     for (r = SetSize; r < MaxLength; ++r)
  22.     {
  23.     double    StirlNum = (double)Stirling2(r-1, SetSize-1);
  24.     P(printf("Stirling2(%3d, %3d) = %.15Le\n", r-1, SetSize-1,
  25.         Stirling2(r-1, SetSize-1)));
  26.  
  27.     ProbCoef /= (double)SetSize;
  28.     *CouponProbs = ProbCoef * StirlNum;
  29.     P(printf("Coupon Probability #%3d = %.15e\n",
  30.         r - SetSize + 1, *CouponProbs));
  31.     ++CouponProbs;
  32.     }
  33.  
  34.     P(printf("Stirling2(%3d, %3d) = %.15Le\n", MaxLength-1, SetSize,
  35.     Stirling2(MaxLength-1, SetSize)));
  36.  
  37.     *CouponProbs =
  38.     1.0 - ProbCoef * (double)Stirling2(MaxLength-1, SetSize);
  39.     P(printf("Coupon Probability #%3d = %.15e\n",
  40.         r - SetSize + 1, *CouponProbs));
  41. }
  42.